package com.dw

import scala.collection.mutable.ListBuffer

/**
 * @Date: 23.6.10 
 * @Author: Hang.Nian.YY
 * @qq: 598196583
 * @Tips: 学大数据 ,到多易教育
 * @Description:
 */
object TestTree {
  def main(args: Array[String]): Unit = {
    val e = new TreeNode("e", ListBuffer[TreeNode]())
    val f1 = new TreeNode("f", ListBuffer[TreeNode]())
    val d = new TreeNode("d", ListBuffer[TreeNode](e, f1))
    val b = new TreeNode("b", ListBuffer[TreeNode](d))
    val p = new TreeNode("p", ListBuffer[TreeNode]())
    val y = new TreeNode("y", ListBuffer[TreeNode]())
    val f2 = new TreeNode("f", ListBuffer[TreeNode]())
    val k = new TreeNode("k", ListBuffer[TreeNode]())
    val x = new TreeNode("x", ListBuffer[TreeNode](p))
    val d2 = new TreeNode("d", ListBuffer[TreeNode](f2, k))
    val c = new TreeNode("c", ListBuffer[TreeNode](x, y, d2))
    val root = new TreeNode("a", ListBuffer[TreeNode](b, c))

    val buffer = new  ListBuffer[(String, Int)]()
    // val buffer = new  ListBuffer[(PageBean, Int)]()

    followPvPlus(root ,buffer )
    buffer.foreach(println)

  }


 def followPvPlus(node: TreeNode , midRes:ListBuffer[(String,Int)]): Int = {
    var pv: Int = 0

    val children = node.children
    if(children!=null && children.size>0){
      pv = children.size
      for (elem <- children) {
        var  url = elem.url
        pv += followPvPlus(elem ,midRes)
      }
    }
    midRes.append((node.url,pv))
   // println((node.url,pv))
    pv
  }

  def follow_pv(node: TreeNode): Int = {
    var pv = 0
    val children = node.children
    if(children!=null && children.size>0){
      pv = children.size
      for (elem <- children) {
        pv += follow_pv(elem)
      }
    }
    pv
  }


}


